//-----------------------------------------------------------------------------
// File: DrawerBandItem.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;

namespace ObjectiveDraw.Platform
{
	/// <summary>
	/// Summary description for DrawerBandItem.
	/// </summary>
	public class DrawerBandItem : Cerebrum.Direct3D.Forms.TabButton, Cerebrum.Windows.Forms.IUiControl, Cerebrum.IReleasable
	{
		public DrawerBandItem():base()
		{
			//
			// TODO: Add constructor logic here
			//
			this.Click += new System.Windows.Forms.MouseEventHandler(DrawerBandItem_Click);
		}

		protected Cerebrum.ObjectHandle m_CommandId;

		public Cerebrum.ObjectHandle CommandId
		{
			get
			{
				return m_CommandId;
			}
			set
			{
				m_CommandId = value;
			}
		}

		protected int m_MergeOrder;
		public int MergeOrder
		{
			get
			{
				return this.m_MergeOrder;
			}
			set
			{
				this.m_MergeOrder = value;
			}
		}

		public event System.ComponentModel.CancelEventHandler InvokeCommand;

		public void AttachCommand(Cerebrum.Windows.Forms.Reflection.UiCommandDescriptor command)
		{
			this.NormalLeaveImage = command.GetNormalLeaveImage();
			this.NormalEnterImage = command.GetNormalEnterImage();
			if(this.NormalEnterImage==null)
				this.NormalEnterImage = this.NormalLeaveImage;
			ObjectiveDraw.Platform.Application _app = ObjectiveDraw.Platform.Application.FromComponent(command.DomainContext);
			ToolBarDrawHelper.InitImageButton(this, _app, this.NormalLeaveImage, this.NormalEnterImage, true);
		}


		#region IReleasable Members

		public bool Release(bool cancel)
		{
			System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(cancel);
			System.ComponentModel.CancelEventHandler handler = (System.ComponentModel.CancelEventHandler)this.GetEventHandlerList()[Cerebrum.Specialized.EventKeys.ReleasingEvent];
			if (handler != null)
				handler(this, e);
			return e.Cancel;
		}

		public event System.ComponentModel.CancelEventHandler Releasing
		{
			add	{	GetEventHandlerList().AddHandler(Cerebrum.Specialized.EventKeys.ReleasingEvent, value);	}
			remove	{	GetEventHandlerList().RemoveHandler(Cerebrum.Specialized.EventKeys.ReleasingEvent, value);	}
		}

		#endregion

		private void DrawerBandItem_Click(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(this.InvokeCommand!=null)
			{
				this.InvokeCommand(sender, new System.ComponentModel.CancelEventArgs(false));
			}
		}
		#region IUiControl Members

		int Cerebrum.Windows.Forms.IUiControl.MergeOrder
		{
			get
			{
				return this.MergeOrder;
			}
		}

		bool Cerebrum.Windows.Forms.IUiControl.Visible
		{
			get
			{
				return this.Visible;
			}
			set
			{
				this.Visible = value;
			}
		}

		Cerebrum.ObjectHandle Cerebrum.Windows.Forms.IUiControl.CommandId
		{
			get
			{
				return this.CommandId;
			}
			set
			{
				this.CommandId = value;
			}
		}

		bool Cerebrum.Windows.Forms.IUiControl.Checked
		{
			get
			{
				return this.Checked;
			}
			set
			{
				this.Checked = value;
			}
		}

		bool Cerebrum.Windows.Forms.IUiControl.Enabled
		{
			get
			{
				return this.Enabled;
			}
			set
			{
				this.Enabled = value;
			}
		}

		event System.ComponentModel.CancelEventHandler Cerebrum.Windows.Forms.IUiControl.InvokeCommand
		{
			add
			{
				this.InvokeCommand += value;
			}
			remove
			{
				this.InvokeCommand -= value;
			}
		}

		void Cerebrum.Windows.Forms.IUiControl.AttachCommand(Cerebrum.Windows.Forms.Reflection.UiCommandDescriptor command)
		{
			this.AttachCommand(command);
		}

		#endregion
	}
}
